package logger;

import java.util.logging.*;

public class Loggfile {

	

	public static final String LOGGER_NAME = Loggfile.class.getSimpleName();
	private Logger logger = null;
	
	public Loggfile (){
		logger = Logger.getLogger(LOGGER_NAME);
		logger.setLevel(Level.INFO);
		
		handler();
	}
	
	
	public static void main(String[] args) {
	
		Loggfile o = new Loggfile();
		o.doStuff();

	}
	
	public void doStuff(){
		logger.fine("Fine messange from main Class");
		logger.info("Info messange from main Class");
		logger.warning("Warning messange from main Class");
		
		OtherClass other = new OtherClass();
		OtherClass2 other2 = new OtherClass2();
	}
	
	private void handler(){
		Handler [] dh = Logger.getLogger("").getHandlers();
		System.out.println(dh.length);
		if (dh.length == 1){
			dh[0].setLevel(Level.WARNING);
		} else{
			throw new RuntimeException("More than one default handler");
		}
		try {
			Handler logHandler = new FileHandler(LOGGER_NAME + "%u/" + "%g/" + "+.log", 1000000, 9);
			logHandler.setLevel(Level.FINE);
			logger.addHandler(logHandler);
		} catch (Exception e) {e.toString();}
		
		
	}
	
}
